//package com.bonc.extractor;
//
//
//import java.awt.BorderLayout;
//import java.awt.Color;
//import java.io.BufferedReader;
//import java.io.FileInputStream;
//import java.io.InputStreamReader;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
//import javax.swing.JFrame;
//import javax.swing.JPanel;
//import javax.swing.WindowConstants;
//
//import com.apporiented.algorithm.clustering.AverageLinkageStrategy;
//import com.apporiented.algorithm.clustering.Cluster;
//import com.apporiented.algorithm.clustering.ClusteringAlgorithm;
//import com.apporiented.algorithm.clustering.DefaultClusteringAlgorithm;
//import com.apporiented.algorithm.clustering.visualization.DendrogramPanel;
//import com.bonc.vectorspacemodel.Corpus;
//import com.bonc.vectorspacemodel.Document;
//import com.bonc.vectorspacemodel.VectorSpaceModel;
//
///**
// * @author donggui@bonc.com.cn
// * @version 2016 2016年6月20日 下午3:53:33
// */
//public class VectorAndClusterChiTester2 {
//
//	public Cluster createSampleCluster(List<Document> documents,double[][] distances){
////		int row = distances.length;
//		int row = documents.size();
//		String[] names = new String[row];
//		for(int i = 0; i < row; i++){
//			names[i] = documents.get(i).getFileName();
//		}
////        String[] names = new String[] { "O1", "O2", "O3", "O4", "O5", "06", "07" };
//        ClusteringAlgorithm alg = new DefaultClusteringAlgorithm();
//        Cluster cluster = alg.performClustering(distances, names, new AverageLinkageStrategy());
//        cluster.toConsole(0);
//        return cluster;		
//	}
//	
//	private void displayCluster(List<Document> documents,double[][] distances){
//        JFrame frame = new JFrame();
//        frame.setSize(400, 300);
//        frame.setLocation(400, 300);
//        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//
//        JPanel content = new JPanel();
//        DendrogramPanel dp = new DendrogramPanel();
//
//        frame.setContentPane(content);
//        content.setBackground(Color.red);
//        content.setLayout(new BorderLayout());
//        content.add(dp, BorderLayout.CENTER);
//        dp.setBackground(Color.WHITE);
//        dp.setLineColor(Color.BLACK);
//        dp.setScaleValueDecimals(0);
//        dp.setScaleValueInterval(1);
//        dp.setShowDistances(false);
//
//        Cluster cluster = createSampleCluster(documents,distances);
//        dp.setModel(cluster);
//        frame.setVisible(true);
//	}
//	
//	public static Map<String, String> loadStopwords(){
//		Map<String, String> stopwords = new ConcurrentHashMap<String, String>();
//		try {
//			System.out.println("[LOAD] Load stopwords.");
////			String filePath = getDictsDir() + "stopwords.txt";
//			String filePath = "C:\\Users\\Administrator\\git\\hierarchical-clustering-java\\src\\main\\resources\\"+ "stopwords.txt";
//			InputStreamReader reader = new InputStreamReader(
//					new FileInputStream(filePath));
//			BufferedReader br = new BufferedReader(reader);
//
//			String line = null;
//			while ((line = br.readLine()) != null) {
//				stopwords.put(line, "");
//			}
//
//			br.close();
//			reader.close();
//			System.out.println("[LOAD] Load stoprwords finished.");
//		} catch (Exception e) {
//			System.out.println(e.getMessage());
//			e.printStackTrace();
//		}
//		return stopwords;
//	}
//	
//
//    
//	public static void main(String[] args) {
//		
//		Map<String, String> stopwords = VectorAndClusterChiTester.loadStopwords();
//		
//		String sPath = "C:\\Users\\Administrator\\git\\hierarchical-clustering-java\\data\\demo\\";
//		List<String> fileNames = MaxentChiTester.getFileList(sPath);
//		
//		ArrayList<Document> documents = new ArrayList<Document>();
////        ArrayList<String> targetValue = new ArrayList<String>();
//        
//		for(String fname:fileNames){
//			Document s1 = new Document(fname, sPath, fname, true, stopwords);
//			documents.add(s1);
//		}		
//			
//		Corpus corpus = new Corpus(documents);
//		
//		VectorSpaceModel vectorSpace = new VectorSpaceModel(corpus);
//		
//		int row = documents.size();
//		double[][] distances = new double[row][row];
//		for (int i = 0; i < row; i++){
//			for (int j = i+1; j< row; j++){
//				Document doci = documents.get(i);
//				Document docj = documents.get(j);
////				distances[i][j] = vectorSpace.jaccardSimilarity(doci, docj);
//				distances[i][j] = 1 - vectorSpace.jaccardSimilarity(doci, docj);
//				distances[j][i] = distances[i][j];
//				distances[i][i] = 0;
//			}
//		}
//		
//		for(int i = 0; i < row; ++i){
//			for(int j = 0; j < row; ++j){
//				System.out.print((1-distances[i][j]) + "\t");
//			}			
//			System.out.println();
//		}		
//		System.out.println();
//		
//		VectorAndClusterChiTester2 tester = new VectorAndClusterChiTester2();
//		tester.displayCluster(documents, distances);
//	}
//}
